﻿$(document).ready(function () {

    getClientsByIdUser();

    setSecurity();
});

function getClientsByIdUser() {

    var pageIndex = 1;
    var pageSize = 10;
    var userId = 1;

    $.ajax({
        url: '/main/getClientsByIdUser?pageIndex=' + pageIndex + '&pageSize=' + pageSize + "&userId=" + userId,
        contentType: 'application/json; charset=utf-8',
        type: 'GET',
        success: function (response, status, error) {
            renderTable(response);
        }
    });
}

function renderTable(jsonData) {

    var table = $('#main-table tbody').empty();

    $.each(jsonData, function (key, value) {

        //var $row = $('<tr> </tr>');
        //$row.append('<td>' + value.CompletedName + '</td>');
        //$row.append('<td>' + value.Gender + '</td>');
        //$row.append('<td>' + value.CreditCard + '</td>');
        //$row.append('<td>' + value.Dni + '</td>');
        //$row.append('<td>' + value.Address + '</td>');
        //$row.append('<td><a href="ClientDetails/index?idClient="' + value.Id + ' class="btn btn-primary" target="_blank"> ver detalles </a></td>');
        //table.append($row);

        var $row = $("<tr> </tr>");
        $row.append("<td>" + value.CompletedName + "</td>");
        $row.append("<td>" + value.Gender + "</td>");
        $row.append("<td>" + value.CreditCard + "</td>");
        $row.append("<td>" + value.Dni + "</td>");
        $row.append("<td>" + value.Address + "</td>");
        $row.append("<td><a  href='ClientDetails/index?idClient=" + value.Id + "' target='_blank' class='btn btn-primary'> ver detalles </a></td>");
        table.append($row);

    });
    
    setSecurity();
}

function setSecurity() {

    $('body').bind("cut copy paste", function (e) {
      
        //e.preventDefault();
        saveSecurityHistory(e);
        return false;
       
    });
    
}

function saveSecurityHistory(event) {
    console.log("event:" + event.type);
}